package regTests;
public class Iteration extends TestStuff{ 
    public int  a;
    public Iteration(int a ){
		this.a = a;
    }
	
	public static void createLoop(int N){
		System.out.println("Starting test iteration, 10000 loops that all create a new object");
		
		Iteration b = new Iteration(0);
		for(int i=0; i< N; i++){
			Iteration c = new Iteration(b.a + 1);
			b = c;
		}
		testAssert(N,b.a);
	}
	
	public static void emptyLoopArr(int N){
		int[] b = new int[N];
		 b[0] =0;
		for(int i=0;i<N-1; i++){
			b[i+1] = b[i]+1;
		}
		testAssert(N-1,b[N-1]);
	}
	public static void emptyLoop(int N){
		System.out.print("Empty loop: ");
		System.out.println(N);
		int b = 0;
		for(int i=0;i<N; i++){
			b = b+1;
		}
		testAssert(N,b);
		System.out.println("\n");
	}
	public static void emptyDoubleLoop(int N){
		System.out.print("Double empty loop: ");
		System.out.println(N);
		int b = 0;
		for(int i=0;i<N;i++){
			for(int y=0;y<N;y++){
				b = b+1;
			}
		}
		testAssert(N*N, b);
		System.out.println("\n");
	}
	
	public static void inlineLoop(){
		System.out.print("Inline loop: ");
		int z=0;
		for(int i=0;i<100;i++){
			
			if(i > 30){
				z += bar(z);
			}else{
				z += 1;
			}
			
		}
		testAssert(31, z);
	}
	
	public static int bar(int b){
		for(int i=b;i>0;i--)
			if(b < 50)
				b--;
			else
				b = foo(b);
		
		return b;
	}
	public static int foo(int i){
		return i + 1;
	}
	
    public static void main(String[] args){
		System.out.println("Starting test iteration");
		emptyLoop(10000000);
		//emptyLoop(10000000);
		emptyDoubleLoop(100);
		
		inlineLoop();
		
    }
	
}